package com.just.fun.sort;

import java.util.Arrays;

public class QuickSortTest1 {
    public static void main(String[] args) {
        System.out.println("快排算法测试");
        int a[]={1,4,3,2,5,6,10,9,33,12,43,54,76,86,13,44,56,99,61,333,564,644,23};
        System.out.println("原始数据："+ Arrays.toString(a));
        long start=System.currentTimeMillis();
        //insertSort(a);
        //selectSort(a);
        //bubbleSort(a);
        quickSort(a,0,a.length-1);
        System.out.println("排序用时："+(System.currentTimeMillis()-start));
        System.out.println("排序后的数据："+Arrays.toString(a));
    }

    public static void quickSort(int[] a,int left,int right){
        if(left>=right){
            System.out.println("排完一波,left:"+left+",right:"+right);
            return;
        }
        int key=a[left];
        int low=left;
        int high=right;
        while (low<high){
            while (low<high&&a[high]>key){
                high--;
            }
            a[low]=a[high];
            while (low<high&&a[low]<key){
                low++;
            }
            a[high]=a[low];
        }
        a[low]=key;
        quickSort(a,left,low-1);
        quickSort(a,high+1,right);
    }
}
